package org.example.bifunction;

import java.util.function.BiFunction;
import java.util.function.Function;

public class Java8BiFunction2c {
    public static void main(String[] args) {
        String result = convert(2,4,(a1,a2) -> Math.pow(a1,a2),(r) -> "Pow: " + r);
        System.err.println(result);
        String result2 = convert(2,4,(a1,a2) -> a1 * a2,(r) -> "Multiply:" + r);
        System.err.println(result2);
        String result3 = convert(2,4,(a1,a2) -> a1 + a2,(r) -> r + "cde");
        System.err.println(result3);
        Integer result4 = convert("100","200",(x,y) -> x + y,r -> Integer.valueOf(r));
        System.err.println(result4);
    }

    public static <A1,A2,R1,R2> R2 convert(A1 a1,A2 a2,
                                           BiFunction<A1,A2,R1> func1,
                                           Function<R1,R2> func2){
        return func1.andThen(func2).apply(a1, a2);
    }
}
